﻿using System;
using System.Data;
using System.Collections.Generic;

using SobFS.Model;
using SobFS.DALFactory;
using SobFS.IDAL;
using SobFS.Common.Database;
using SobFS.Common;
namespace SobFS.BLL
{
    /// <summary>
    /// SysFunctionMenu
    /// </summary>
    public partial class SysFunctionMenu
    {
        private readonly ISysFunctionMenu dal = DataAccess.CreateSysFunctionMenu();
        public SysFunctionMenu()
        { }
        #region  Method

        /// <summary>
        /// 得到最大ID
        /// </summary>
        public int GetMaxId()
        {
            return dal.GetMaxId();
        }

        /// <summary>
        /// 是否存在该记录
        /// </summary>
        public bool Exists(int Id)
        {
            return dal.Exists(Id);
        }

        /// <summary>
        /// 增加一条数据
        /// </summary>
        public bool Add(SobFS.Model.SysFunctionMenu model)
        {
            return dal.Add(model);
        }

        /// <summary>
        /// 更新一条数据
        /// </summary>
        public bool Update(SobFS.Model.SysFunctionMenu model)
        {
            return dal.Update(model);
        }

        /// <summary>
        /// 删除一条数据
        /// </summary>
        public bool Delete(int Id)
        {

            return dal.Delete(Id);
        }
        /// <summary>
        /// 删除一条数据
        /// </summary>
        public bool DeleteList(string Idlist)
        {
            return dal.DeleteList(Idlist);
        }

        /// <summary>
        /// 得到一个对象实体
        /// </summary>
        public SobFS.Model.SysFunctionMenu GetModel(int Id)
        {

            return dal.GetModel(Id);
        }      

        /// <summary>
        /// 获得数据列表
        /// </summary>
        public DataSet GetList(string strWhere)
        {
            return dal.GetList(strWhere);
        }
        /// <summary>
        /// 获得数据列表
        /// </summary>
        public List<SobFS.Model.SysFunctionMenu> GetModelList(string strWhere)
        {
            DataSet ds = dal.GetList(strWhere);
            return DataTableToList(ds.Tables[0]);
        }
        /// <summary>
        /// 获得数据列表
        /// </summary>
        public List<SobFS.Model.SysFunctionMenu> DataTableToList(DataTable dt)
        {
            List<SobFS.Model.SysFunctionMenu> modelList = new List<SobFS.Model.SysFunctionMenu>();
            int rowsCount = dt.Rows.Count;
            if (rowsCount > 0)
            {
                SobFS.Model.SysFunctionMenu model;
                for (int n = 0; n < rowsCount; n++)
                {
                    model = new SobFS.Model.SysFunctionMenu();
                    if (dt.Rows[n]["Id"] != null && dt.Rows[n]["Id"].ToString() != "")
                    {
                        model.Id = int.Parse(dt.Rows[n]["Id"].ToString());
                    }
                    if (dt.Rows[n]["ParentId"] != null && dt.Rows[n]["ParentId"].ToString() != "")
                    {
                        model.ParentId = int.Parse(dt.Rows[n]["ParentId"].ToString());
                    }
                    if (dt.Rows[n]["MenuType"] != null && dt.Rows[n]["MenuType"].ToString() != "")
                    {
                        model.MenuType = dt.Rows[n]["MenuType"].ToString();
                    }
                    if (dt.Rows[n]["Code"] != null && dt.Rows[n]["Code"].ToString() != "")
                    {
                        model.Code = dt.Rows[n]["Code"].ToString();
                    }
                    if (dt.Rows[n]["Name"] != null && dt.Rows[n]["Name"].ToString() != "")
                    {
                        model.Name = dt.Rows[n]["Name"].ToString();
                    }
                    if (dt.Rows[n]["URL"] != null && dt.Rows[n]["URL"].ToString() != "")
                    {
                        model.URL = dt.Rows[n]["URL"].ToString();
                    }
                    if (dt.Rows[n]["Position"] != null && dt.Rows[n]["Position"].ToString() != "")
                    {
                        model.Position = int.Parse(dt.Rows[n]["Position"].ToString());
                    }
                    if (dt.Rows[n]["Description"] != null && dt.Rows[n]["Description"].ToString() != "")
                    {
                        model.Description = dt.Rows[n]["Description"].ToString();
                    }
                    if (dt.Rows[n]["IsObsoleted"] != null && dt.Rows[n]["IsObsoleted"].ToString() != "")
                    {
                        if ((dt.Rows[n]["IsObsoleted"].ToString() == "1") || (dt.Rows[n]["IsObsoleted"].ToString().ToLower() == "true"))
                        {
                            model.IsObsoleted = true;
                        }
                        else
                        {
                            model.IsObsoleted = false;
                        }
                    }
                    if (dt.Rows[n]["IsEnabled"] != null && dt.Rows[n]["IsEnabled"].ToString() != "")
                    {
                        if ((dt.Rows[n]["IsEnabled"].ToString() == "1") || (dt.Rows[n]["IsEnabled"].ToString().ToLower() == "true"))
                        {
                            model.IsEnabled = true;
                        }
                        else
                        {
                            model.IsEnabled = false;
                        }
                    }
                    modelList.Add(model);
                }
            }
            return modelList;
        }

        /// <summary>
        /// 获得数据列表
        /// </summary>
        public DataSet GetAllList()
        {
            return GetList("");
        }
              
        /// <summary>
        /// 分页获取数据列表
        /// </summary>
        //public DataSet GetList(int PageSize,int PageIndex,string strWhere)
        //{
        //return dal.GetList(PageSize,PageIndex,strWhere);
        //}

        #endregion  Method
	
    }
}

